--[[***************************
   Copyright (c) 2012 TPV R&D Center Brazil
   All Rights Reserved
 ***********************]]

--- toolkit.component.ProgressBar

local ProgressBar = Box:new()

function ProgressBar:new(o)
   if(type(o) ~= 'table') then
      o = {}
   end

   local newProgress = Box:new(o)
   
   newProgress.parent = nil

   newProgress.backContent = nil
   newProgress.barContent = nil

   newProgress.componentType = "ProgressBar"

   newProgress.minValue = o.minValue or 0
   newProgress.maxValue = o.minValue or 100

   newProgress.noLabel = o.noLabel or false

   newProgress.value = newProgress.minValue

   tmpLabel = Label:new({width = 90})
   tmpLabel:setActivated({size = 35, color = {241, 241, 241, 255}, style = 'Bold'})

   newProgress.label = o.label or tmpLabel
   newProgress.label:setText('0%')

   newProgress.backGround = o.backGround or nil
   newProgress.foreGround = o.foreGround or nil

   --generate an object
   setmetatable(newProgress, self)
   self.__index = self

   return newProgress
end

function ProgressBar:setValue(newValue)
   if(newValue ~= self.value) then
      if(newValue < self.minValue) then
         newValue = self.minValue
      elseif(newValue > self.maxValue) then
         newValue = self.maxValue
      end
      --set new value
      self.value = newValue
      if(self.label ~= nil) then
         self.label:setText(math.floor(self.value) .. "%")
      end
   end

   self.parent:updateProgressBar(self)
end

function ProgressBar:dispose()
   self.backContent = nil
   self.barContent = nil
   collectgarbage()
end

return ProgressBar
